<html>

<head>

<?php

$time_start = microtime(true);
include "../includes/constants.php";
include "../includes/functions.php";

function OutputField($FieldName="",$DisplayName="",$InputSize=1,$Break=TRUE) {
	global $db_row;
	if ($DisplayName == "") {$DisplayName = ucfirst($FieldName);};
	if ($InputSize == "") {$InputSize = 1;};
	echo $DisplayName . ": <input type=\"text\" size=\"" . $InputSize . "\" name=\"" . $FieldName . "\" value=\"" . $db_row[$FieldName] . "\">";
	if ($Break) {
		echo "<br>";
	};
	echo "\n";
};

?>

<title>EQ Emu - Edit Item</title>

<script src="../includes/functions.js"></script>

</head>

<body onload="document.NoID.id.focus()">

<form name="NoID" method="GET" action="">
	Enter ID: <input type="text" name="id" size="2" value="<?php echo $_GET["id"];?>">
	<button type="submit">Get</button>
	<button onclick="OpenItem('index.php?id=' + document.NoID.id.value)">View</button><br>
</form>

<?php

if ($_POST["id"]) {
	$query_update = "UPDATE items SET ";
	foreach($_POST as $Key => $Value) {
		if ($Value != "") {
			$query_update .= " " . $Key . "='" . $Value . "',";
		};
	};
	$query_update = substr($query_update,0,-1); // Erase last comma
	$query_update .= " WHERE id='" . $_GET["id"] . "'";
	$result_update = mysql_query($query_update,$db);
	if ($result_update) {
		echo "<font color=\"blue\">\"";
		GetItemName($_POST["id"]);
		echo "\" Updated Successfully!</font>";
	} else {
		$error = mysql_error();
		echo "<font color=\"red\">Update to \"";
		GetItemName($_POST["id"]);
		echo "\" Unsuccessful!</font>";
		echo " - <font color=\"silver\">[" . $error . "]</font>";
	};
};

if (isset($_GET["id"])) {

$query = "SELECT * FROM items WHERE id='" . $_GET["id"] . "'";
$result = mysql_query($query,$db);
$db_row = mysql_fetch_array($result);

echo "<form name=\"EditItem\" method=\"POST\" action=\"\">
<button type=\"submit\">Update</button> <button type=\"reset\">Reset</button><br>
<br>\n";

// OutputField(,'','');
OutputField(id,'ID',2,0);
OutputField(minstatus,'',1);
OutputField(Name,'',40,0);
OutputField(icon,'','',0);
	echo "\t<button onclick=\"OpenItemIcon('../images/icons-items/' + icon.value + '.gif');return false\">View</button><br>\n";
OutputField(magic,'Magic Item',1,0);
OutputField(loregroup,'Lore Group',1,0);
OutputField(nodrop,'No Trade',1,0);
OutputField(norent,'','',0);
OutputField(artifactflag,'','');
OutputField(maxcharges,'','');
OutputField(lore,'',40);
OutputField(slots,'Slot',2);
OutputField(itemtype,'Skill','',0);
OutputField(delay,'','');
OutputField(damage,'','',0);
OutputField(ac,'AC',2);
OutputField(elemdmgtype,'','',0);
OutputField(elemdmgamt,'','');
OutputField(banedmgbody,'','',0);
OutputField(banedmgamt,'','',0);
OutputField(banedmgrace,'','',0);
OutputField(banedmgraceamt,'','');
OutputField(skillmodtype,'','',0);
OutputField(skillmodvalue,'','');
OutputField(proceffect,'','',0);
OutputField(proctype,'','',0);
OutputField(proclevel2,'','',0);
OutputField(proclevel,'','',0);
OutputField(procrate,'','');
// OutputField(procunk1);
// OutputField(procunk2);
// OutputField(procunk3);
// OutputField(procunk4);
// OutputField(procunk5);
// OutputField(procunk6);
// OutputField(procunk7);
OutputField(clickeffect,'Effect','',0);
OutputField(clicktype,'','',0);
OutputField(clicklevel2,'','',0);
OutputField(clicklevel,'','',0);
OutputField(casttime,'','',0);
OutputField(casttime_,'','');
// OutputField(clickunk5);
// OutputField(clickunk6);
// OutputField(clickunk7);
OutputField(recastdelay,'Recast Delay','',0);
OutputField(recasttype,'Recast Type','');
OutputField(focuseffect,'Focus Effect','',0);
OutputField(focustype,'','',0);
OutputField(focuslevel2,'','',0);
OutputField(focuslevel,'','');
// OutputField(focusunk1);
// OutputField(focusunk2);
// OutputField(focusunk3);
// OutputField(focusunk4);
// OutputField(focusunk5);
// OutputField(focusunk6);
// OutputField(focusunk7);
OutputField(worneffect,'','',0);
OutputField(worntype,'','',0);
OutputField(wornlevel2,'','',0);
OutputField(wornlevel,'','');
// OutputField(wornunk1);
// OutputField(wornunk2);
// OutputField(wornunk3);
// OutputField(wornunk4);
// OutputField(wornunk5);
// OutputField(wornunk6);
// OutputField(wornunk7);
OutputField(scrolleffect,'','',0);
OutputField(scrolltype,'','',0);
OutputField(scrolllevel2,'','',0);
OutputField(scrolllevel,'','');
// OutputField(scrollunk1);
// OutputField(scrollunk2);
// OutputField(scrollunk3);
// OutputField(scrollunk4);
// OutputField(scrollunk5);
// OutputField(scrollunk6);
// OutputField(scrollunk7);
OutputField(astr,'STR','',0);
OutputField(adex,'DEX','',0);
OutputField(asta,'STA','',0);
OutputField(acha,'CHA','',0);
OutputField(awis,'WIS','',0);
OutputField(aint,'INT','',0);
OutputField(aagi,'AGI',1,0);
OutputField(hp,'HP','',0);
OutputField(mana,'','',0);
OutputField(endur,'Endurance','');
OutputField(fr,'SV FIRE','',0);
OutputField(dr,'SV DISEASE','',0);
OutputField(cr,'SV COLD','',0);
OutputField(mr,'SV MAGIC','',0);
OutputField(pr,'SV POISON','',0);
OutputField(svcorruption);
OutputField(attack,'Attack','');
OutputField(regen,'Regeneration','');
OutputField(manaregen,'Mana Regeneration','');
OutputField(enduranceregen,'Endurance Regeneration','');
OutputField(damageshield,'Damage Shield','');
OutputField(combateffects,'Combat Effects','',0);
OutputField(shielding,'Shielding','',0);
OutputField(spellshield,'','',0);
OutputField(avoidance,'Avoidance','',0);
OutputField(accuracy,'','',0);
OutputField(stunresist,'','',0);
OutputField(strikethrough,'','');
OutputField(dotshielding,'','');
OutputField(haste,'','');
OutputField(bardtype,'','',0);
OutputField(bardvalue,'','');
OutputField(extradmgskill,'','',0);
OutputField(extradmgamt,'','');
OutputField(reclevel,'Recommended Level','',0);
OutputField(reqlevel,'Required Level','');
OutputField(weight,'WT','',0);
OutputField(range,'','',0);
OutputField(size,'','',0);
OutputField(bagwr,'','');
OutputField(bagslots,'','',0);
OutputField(bagsize,'','',0);
OutputField(bagtype,'','');
OutputField(classes,'Class',2);
OutputField(races,'Race',2);
OutputField(deity,'','');
OutputField(augrestrict,'','');
OutputField(augslot1type,'','');
// OutputField(augslot1unk,'','');
// OutputField(augslot1unk2);
OutputField(augslot2type,'','');
// OutputField(augslot2unk,'','');
// OutputField(augslot2unk2);
OutputField(augslot3type,'','');
// OutputField(augslot3unk,'','');
// OutputField(augslot3unk2);
OutputField(augslot4type,'','');
// OutputField(augslot4unk,'','');
// OutputField(augslot4unk2);
OutputField(augslot5type,'','');
// OutputField(augslot5unk,'','');
// OutputField(augslot5unk2);
OutputField(augtype,'',8);
OutputField(augdistiller,'',2,0);
	echo "\t<button onclick=\"OpenItem('index.php?id=' + augdistiller.value);return false\">View</button><br>\n";

echo "<br>\n";
OutputField(book,'','');
OutputField(charmfile,'',15,0);
	echo "\t<button onclick=\"OpenBook('" . $db_row["charmfile"] . "');return false\">Read</button><br>\n";
OutputField(charmfileid,'','');
OutputField(color,'','7');
OutputField(price,'','');
OutputField(factionamt1,'','');
OutputField(factionamt2,'','');
OutputField(factionamt3,'','');
OutputField(factionamt4,'','');
OutputField(factionmod1,'','');
OutputField(factionmod2,'','');
OutputField(factionmod3,'','');
OutputField(factionmod4,'','');
OutputField(filename,'',15,'');
	echo "\t<button onclick=\"OpenBook('" . $db_row["filename"] . "');return false\">Read</button><br>\n";
OutputField(fvnodrop,'','');
OutputField(idfile,'','3');
OutputField(itemclass,'','');
OutputField(ldonprice,'','');
OutputField(ldontheme,'','');
OutputField(ldonsold,'','');
OutputField(light,'','');
OutputField(material,'','');
OutputField(pendingloreflag,'','');
OutputField(recskill,'','');
OutputField(sellrate,'','');
OutputField(summonedflag,'','');
OutputField(tradeskills,'','');
OutputField(favor,'','');
// OutputField(unknown002,'','');
// OutputField(unknown003,'','');
// OutputField(unknown005,'','');
// OutputField(unknown007,'','');
// OutputField(unknown018,'','');
// OutputField(unknown019,'','');
// OutputField(unknown020,'','');
// OutputField(UNK012,'','');
// OutputField(UNK013,'','');
OutputField(benefitflag,'','');
// OutputField(unknown061,'','');
// OutputField(UNK054,'','');
// OutputField(unknown067,'','');
// OutputField(unknown069,'','');
// OutputField(UNK59,'','');
// OutputField(UNK061,'','');
// OutputField(unknown081,'','');
// OutputField(unknown105,'','');
OutputField(booktype,'','');
// OutputField(unknown122,'','');
// OutputField(unknown123,'','');
// OutputField(unknown124,'','');
OutputField(guildfavor,'','');
// OutputField(unknown128,'','');
// OutputField(UNK123,'','');
// OutputField(UNK124,'','');
OutputField(attuneable,'','');
OutputField(nopet,'','');
// OutputField(unknown133,'','');
OutputField(updated,'','15');
OutputField(comment,'','');
// OutputField(UNK127,'','');
OutputField(pointtype,'','');
OutputField(potionbelt,'','');
OutputField(potionbeltslots,'','');
OutputField(stackable,'','');
OutputField(stacksize,'','');
OutputField(notransfer,'','');
// OutputField(UNK134,'','');
// OutputField(UNK137,'','');
// OutputField(UNK142,'','');
// OutputField(UNK147,'','');
// OutputField(UNK152,'','');
// OutputField(UNK157,'','');
OutputField(serialized,'','15');
OutputField(verified,'','15');
OutputField(serialization,'','');
OutputField(source,'','10');
// OutputField(UNK033,'','');
OutputField(lorefile);
// OutputField(UNK014);
// OutputField(UNK038);
// OutputField(UNK060);
// OutputField(UNK098);
// OutputField(UNK109);
// OutputField(UNK120);
// OutputField(UNK121);
OutputField(questitemflag);
// OutputField(UNK131);
// OutputField(UNK132);
// OutputField(UNK193);
OutputField(purity);
OutputField(evolvinglevel);
// OutputField(UNK129);

echo "<br>
<button type=\"submit\">Update</button> <button type=\"reset\">Reset</button>
</form>";

};

?>

</body>

</html>